package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.entity.lindi.vo.tradeapplicationoperator.LindiTradeApplicationOperatorVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationOperatorFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 林地交易申请操作 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiTradeApplicationOperatorFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationOperatorFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationOperatorFeignClientFallbackFactory.class);

    @Override
    public LindiTradeApplicationOperatorFeignClient create(Throwable cause){
        return new LindiTradeApplicationOperatorFeignClient(){
            @Override
            public R<?> addTradeApplicationOperator(LindiTradeApplicationOperatorVO operatorVO){
                logServiceUnavailable("添加交易申请操作", operatorVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationOperatorByTradeApplicationOperatorId(Long tradeApplicationOperatorId){
                logServiceUnavailable("删除交易申请操作", tradeApplicationOperatorId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationOperatorByTradeApplicationOperatorId(LindiTradeApplicationOperatorVO operatorVO){
                logServiceUnavailable("修改交易申请操作", operatorVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<List<LindiTradeApplicationOperatorVO>> getTradeApplicationOperatorsByTradeApplicationId(Long tradeApplicationId){
                logServiceUnavailable("根据交易申请ID查询操作记录", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }
        };
    }
}